Skip to content

fix(python): isolate filtered batch sampler shuffle state - #11721

Open
zhangyue19921010 wants to merge 1 commit into
lance-format:mainfrom
zhangyue19921010:fix/python-filtered-batch-shuffle
Open

zhangyue19921010 wants to merge 1 commit into
lance-format:mainfrom
zhangyue19921010:fix/python-filtered-batch-shuffle

Conversation

@zhangyue19921010

Copy link
Copy Markdown
Collaborator

Problem

Two filtered ShardedBatchSampler iterators with the same seed and epoch can yield different orders when consumed together. Each draw for the next shuffle priority uses Python's global random generator.

Solution

Initialize a generator inside each randomized filtered traversal and use it for the shuffle priorities.

Result

On a two-fragment dataset, interleaved scans reproduce the uninterrupted order on both ranks. Caller-side random draws also leave that order intact, and the filtered shuffle preserves the caller's random state.

Python lint and all 125 CPU sampler and persistent-worker cases passed. The CUDA-marked test_pytorch_integration fails on both main and this branch because it passes the unsupported total_num_rows argument to ShardedBatchSampler.

Fixes #11720

Problem

Filtered batch iterators draw shuffle priorities from Python's global
generator between yields. Interleaving iterators with the same seed and
epoch changes their order.

Solution

Give each randomized filtered traversal its own generator initialized
with the sampler's seed and epoch.

Result

Interleaved iterators reproduce the uninterrupted order on each rank.
The filtered shuffle leaves the caller's random state intact.

@claude claude Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Claude Code Review

This pull request is from a fork — automated review is disabled. A repository maintainer can comment @claude review to run a one-time review.

@github-actions github-actions Bot added A-python Python bindings bug Something isn't working labels Dec 2, 2026

@lance-gatekeeper lance-gatekeeper Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Gate recommendation: approve.

The iterator-local generator fixes the shared random-state interference while preserving seeded batch order and shard membership.

@lance-gatekeeper lance-gatekeeper Bot added the K-approved Latest Gatekeeper recommendation permits acceptance. label Dec 2, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-python Python bindings bug Something isn't working K-approved Latest Gatekeeper recommendation permits acceptance.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug: interleaved filtered sampler iterators change seeded batch order

1 participant